package com.powerhua.oa.assistant.meeting;

import com.powerhua.core.base.BaseManager;
import com.powerhua.core.bean.BeansRegisterLocator;
import com.powerhua.core.utils.CommonUtils;
import com.powerhua.core.web.IServletAction;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author Brian.Xie
 */
public class MeetingServletAction implements IServletAction {

    private static final Log LOG = LogFactory.getLog(MeetingServletAction.class);
    private BaseManager manager;

    @Override
    public String doAction(HttpServletRequest request) {
        String result = "";
        Map map = request.getParameterMap();
        String action = request.getParameter("a");

        manager = (BaseManager) BeansRegisterLocator.getBean("coreBaseManager");
        if ("save".equals(action)) {
        } else if ("delete".equals(action)) {
        } else if ("list".equals(action)) {
            String pageSize = request.getParameter("pageSize");
            String pageNum = request.getParameter("pageNum");
            int intPageSize = CommonUtils.converStr2Int(pageSize);
            int intPageNum = CommonUtils.converStr2Int(pageNum);
            if (intPageSize == 0) {
                intPageSize = 30;
            }
            if (intPageNum == 0) {
                intPageNum = 1;
            }
            result = list(map, intPageSize, intPageNum);
        } else if ("update".equals(action)) {
        } else if ("getObjectById".equals(action)) {
        } else {
            // TODO 输出错误编码与内容
            result = "error";
        }

        //
        return result;
    }

    /**
     * 
     * @param map
     * @param intPageSize
     * @param intPageNum
     * @return
     */
    private String list(Map map, int intPageSize, int intPageNum) {
        String countSql = "select count(id_) from tb_meeting";
        String listSql = "select id_,name_,converner_id_,date_,meeting_room_id_," +
            "start_time_,end_time_,desc_,user_id_,create_date_,modify_date_ from" +
            " tb_meeting";
        List<String> colNames = new ArrayList<String>();
        List<String> types = new ArrayList<String>();
        colNames.add("id_");
        types.add("varchar");
        colNames.add("name_");
        types.add("varchar");
        colNames.add("converner_id_");
        types.add("varchar");
        colNames.add("date_");
        types.add("timestamp");
        colNames.add("meeting_room_id_");
        types.add("varchar");
        colNames.add("start_time_");
        types.add("varchar");
        colNames.add("end_time_");
        types.add("varchar");
        colNames.add("desc_");
        types.add("varchar");
        colNames.add("user_id_");
        types.add("varchar");
        colNames.add("create_date_");
        types.add("timestamp");
        colNames.add("modify_date_");
        types.add("timestamp");

        String result = manager.getListDao().list(map, countSql, listSql, colNames, types,
            intPageSize, intPageNum);
        return result;
    }
}
